#include <stdio.h>
#define ROW 3
#define COL 5

void get_input(int row,int col, double matrix[row][col]);
double avg_array(int size, double array[size]);
double avg_matrix(int row,int col, double matrix[row][col]);
double max_in_matrix(int row,int col, double matrix[row][col]);
void print_matrix(int row,int col, double matrix[row][col]);
int main(){
    double matrix[ROW][COL];
    get_input(ROW, COL, matrix);
    printf("你输入的数如下:\n");
    print_matrix(ROW, COL, matrix);
    for (int i = 0; i < ROW; ++i) {
        printf("第%d行的平均值是:%f\n", i+1, avg_array(COL, matrix[i]));
    }
    printf("所有数平均值是:%f\n", avg_matrix(ROW, COL, matrix));
    printf("所有数中最大值是:%f\n", max_in_matrix(ROW, COL, matrix));

    return 0;
}
void get_input(int row,int col, double matrix[row][col]){
    printf("输入3X5个数，每次输入5个。\n");
    for (int i = 0; i < row; ++i) {
        printf("请输入第%d组数:", i+1);
        for (int j = 0; j < col; ++j) {
            scanf("%lf",&(matrix[i][j]));
        }
        printf("\n");
    }

}

double avg_array(int size, double array[size]){
    double sum = 0.0;
    for (int i = 0; i < size; ++i) {
        sum += array[i];
    }
    return sum / size;
}

double avg_matrix(int row,int col, double matrix[row][col]){
    double sum = 0.0;
    for (int i = 0; i < row; ++i) {
        for (int j = 0; j < col; ++j) {
            sum += matrix[i][j];
        }
    }
    return sum / (row*col);
}

double max_in_matrix(int row,int col, double matrix[row][col]){
    double max = matrix[0][0];
    for (int i = 0; i < row; ++i) {
        for (int j = 0; j < col; ++j) {
            if (max < matrix[i][j]) {
                max = matrix[i][j];
            }
        }
    }
    return max;
}

void print_matrix(int row,int col, double matrix[row][col]){
    for (int i = 0; i < row; ++i) {
        for (int j = 0; j < col; ++j) {
            printf("%.2f\t", matrix[i][j]);
        }
        printf("\n");
    }
}
